public class Test {
}
public class Solution {
    public TreeNode head = null;
    public TreeNode prev = null;
    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree == null)
            return null;
        Convert(pRootOfTree.left);
        if(prev == null){
            head = pRootOfTree;
            prev = pRootOfTree;
        }else{
            prev.right = pRootOfTree;
            pRootOfTree.left = prev;
            prev = pRootOfTree;
        }
        Convert(pRootOfTree.right);
        return head;
    }
}
class Solution {
    public int maxSubarraySumCircular(int[] nums) {
        int maxS = Integer.MIN_VALUE;
        int minS = 0;
        int maxF = 0;
        int minF = 0;
        int sum = 0;
        for(int x:nums){
            maxF = Math.max(maxF,0)+x;
            maxS = Math.max(maxS,maxF);
            minF = Math.min(minF,0)+x;
            minS = Math.min(minS,minF);
            sum+=x;
        }
        return sum == minF ? maxS : Math.max(maxS,sum-minS);
    }
}
